<?php

declare(strict_types=1);

namespace App\Crontab;

use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Contract\StdoutLoggerInterface;
use Psr\Container\ContainerInterface;

/**
 * 定时任务示例
 */
#[Crontab(name: "ExampleTask", rule: "*/5 * * * *", callback: "execute", memo: "每 5 分钟执行一次")]
class ExampleCrontab
{
    private StdoutLoggerInterface $logger;

    public function __construct(ContainerInterface $container)
    {
        $this->logger = $container->get(StdoutLoggerInterface::class);
    }

    public function execute()
    {
        // 这里写你要执行的任务逻辑
        $this->logger->info("定时任务执行：" . date('Y-m-d H:i:s'));
    }
}
